package com.wwwarehouse.carddesk.constant;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.android.arouter.utils.TextUtils;
import com.alibaba.fastjson.JSONObject;
import com.wwwarehouse.common.bean.carddesk.CardDeskMessageStableCardBean;
import com.wwwarehouse.common.tools.LogUtils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static com.wwwarehouse.common.activity.base.BaseApplication.sp;

/**
 * author ：minifly
 * date: 2017/9/26
 * time: 14:14
 * desc: 信息卡片跳转arouter路径确定
 */
public class MessageRouterConstant {

    public static Fragment goPath(String type) {
        String to = "";
        switch (type) {
            //我创建的
            case "MY_BU_ID":
                to = "/UserCenter/BusinessInfoViewPagerFragment";
                break;
            //我的客户
            case "MY_CLIENT":
                to = "/UserCenter/BusinessInfoViewPagerFragment";
                break;
            //资源汇总
            case "RESOURCE_SUMMARY":
                //type	string	   "1"-物、"0"-资源
                to = "/ResourceCenter/GoodsInfomationCreateItemFragment";
                break;
            //实物信息
            case "ITEM_REALITY_INFO":
                to = "/ResourceCenter/GoodsInfomationCreateItemFragment";
                break;
            //陈超 邀请用户
            case "INVITE_USER_COUNT":
                to = "/taskCenter/InviteRankingFragment";
                break;
            //冯辉的 订单获取监控
            case "ORDER_MONITOR":
                to = "/common/BridgeWebView";
                break;
            //陈杰，消息列表
            case "MESSAGE_MANAGE":
                to = "/app_module/NotificationListFragment";
                break;
            //陈杰 销售库存统计
            case "SALES_INVENTORY_STATISTICS":
                to = "/ResourceCenter/SalesInventoryStatisticsListFragment";
                break;
            //客户档案信息 信息卡 小克
            case "CUSTOMER_PROFILE":
                to = "/UserCenter/BRCustomerFileCheckFragment";
                break;
            //郑旺 契约
            case "AdjustContract":
                to = "/contract/TerminationOrderViewPagerFragment";
                break;
            //郑旺 契约
            case "AdjustContractPush":
                to = "/contract/ConfirmTerminateOrderFragment";
                break;
            //颜鹏庆 资源效率评估
            case "RESOURCE_EFFICIENCY_ASSESS":
                to = "/ResourceCenter/ResourceEfficiencyEvaluationFragment";
                break;
            //颜鹏庆 任务分配规则
            case "ASSIGN_TASK_RULES":
                to = "/ResourceCenter/EditTaskRuleFragment";
                break;
            //小克 供应商档案信息
            case "SUPPLIER_PROFILE":
                to = "/UserCenter/BRCustomerFileCheckFragment";
                break;
            //郑旺 我卖出的
            case "SOLD_ORDER":
                to = "/contract/BuyViewPagerFragment";
                break;
            //郑旺 我买到的
            case "BOUGHT_ORDER":
                to = "/contract/BuyViewPagerFragment";
                break;
            //老王   企业钱仓
            case "ACCOUNT_INFO":
                to = "/FinancialCenter/MoneyHouseFragment";
                break;
            //小胖
            case "PUBLISH_RESOURCE_INFO":
                to = "/contract/ReleaseSupplyListPagerFragment";
                break;
            default:
                break;


        }
        Fragment fg = null;
        if (!TextUtils.isEmpty(to)) {
            try {
                fg = (Fragment) ARouter.getInstance().build(to).navigation();
            } catch (Exception e) {
                LogUtils.showErrLog("" + e.getStackTrace());
                fg = null;
            }
        }

        return fg;
    }

    /**
     * 设置budle的值
     * @param fragment
     * @param tasksBean
     */
    public static void setBundle(Fragment fragment,CardDeskMessageStableCardBean.TasksBean tasksBean){
        Bundle bundle = new Bundle();

        switch (tasksBean.getTaskType()) {
            //我创建的
            case "MY_BU_ID":
                bundle.putString("type", "1");
                if (judgeNull(tasksBean)) {
                    bundle.putString("cardname", tasksBean.getTaskName());
                }
                break;
            //我的客户
            case "MY_CLIENT":
                bundle.putString("type", "2");
                if (judgeNull(tasksBean)){
                    bundle.putString("cardname", tasksBean.getTaskName());
                }
                break;
            //资源汇总
            case "RESOURCE_SUMMARY":
                bundle.putString("type", "0");
                break;
            //实物信息
            case "ITEM_REALITY_INFO":
                bundle.putString("type", "1");
                break;
            //陈超 邀请用户
            case "INVITE_USER_COUNT":
                bundle.putString("type", "1");
                break;
            //冯辉的 订单获取监控
            case "ORDER_MONITOR":
                Map<String, Object> paramsMap = new HashMap<>();
                paramsMap.put("token", sp.getValue("sp_token"));
                // TODO: 2017/10/10 0010 shopId先写死
                paramsMap.put("shopId", "251901");
                paramsMap.put("shopName", "");
                JSONObject json = new JSONObject(paramsMap);
                bundle.putString("title", "订单获取监控");
                bundle.putString("outSiteTitle", "订单下载监控说明");
                bundle.putString("url", "http://192.168.6.31/app/OrderMonitor/");
                bundle.putString("oppositeUrl", "http://192.168.72.177:8888/OrderMonitorInstruction/");
                bundle.putString("data", json.toString());
                break;
            //陈杰，消息列表
            case "MESSAGE_MANAGE":
                bundle.putString("type", "1");
                break;
            //陈杰 销售库存统计
            case "SALES_INVENTORY_STATISTICS":
                bundle.putString("type", "1");
                bundle.putParcelable("data",tasksBean);
                break;
            //客户档案信息 信息卡 小克
            case "CUSTOMER_PROFILE":
                bundle.putParcelable("data",tasksBean);
                break;
            //郑旺 契约
            case "AdjustContract":
                bundle.putParcelable("data",tasksBean);
                break;
            //郑旺 契约
            case "AdjustContractPush":
                bundle.putParcelable("data",tasksBean);
                break;
            //颜鹏庆 资源效率评估
            case "RESOURCE_EFFICIENCY_ASSESS":
                bundle.putParcelable("data",tasksBean);
                break;
            //颜鹏庆 任务分配规则
            case "ASSIGN_TASK_RULES":
                bundle.putParcelable("data",tasksBean);
                break;
            //小克 供应商档案信息
            case "SUPPLIER_PROFILE":
                bundle.putParcelable("data",tasksBean);
                break;
            //郑旺 我卖出的
            case "SOLD_ORDER":
                bundle.putParcelable("data",tasksBean);
                bundle.putInt("flag" ,2);
                break;
            //郑旺 我买到的
            case "BOUGHT_ORDER":
                bundle.putParcelable("data",tasksBean);
                bundle.putInt("flag" ,1);
                break;
            //老王   企业钱仓
            case "ACCOUNT_INFO":
                bundle.putParcelable("data",tasksBean);
                break;
            //小胖
            case "PUBLISH_RESOURCE_INFO":
                bundle.putParcelable("data",tasksBean);
                bundle.putString("type","info");
                break;
            default:

                break;
        }
        fragment.setArguments(bundle);
    }

    public static boolean judgeNull(CardDeskMessageStableCardBean.TasksBean tasksBean) {
        if (tasksBean == null) {
            return false;
        }
        return true;
    }

    /**
     * 处理顶业数据
     */
    public static void dealData(CardDeskMessageStableCardBean allBean,CardDeskMessageStableCardBean.TasksBean tasksBean){
        List<CardDeskMessageStableCardBean.TasksBeanBuidNames> names = new LinkedList<>();

        for(CardDeskMessageStableCardBean.BuIdsBean buIdsBean: allBean.getBuIds()){
            for(String businessId : tasksBean.getBusinessIds()){
                if(buIdsBean.getBuId().equals(businessId)){
                    names.add(new CardDeskMessageStableCardBean.TasksBeanBuidNames(buIdsBean.getBuName(),buIdsBean.getBuId()));
                }
            }
        }
        tasksBean.setTasksBeanBuidNames(names);
    }
}
